package com.iss.yunpan.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.iss.yunpan.entity.ShareContent;
import com.iss.yunpan.service.ShareService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class ShareController {
    @Autowired
    private ShareService service;

    @RequestMapping("getShareFile")
    @ResponseBody
    public Map<String,Object> getShareFile(String shareName,int page,int limit){
        Map<String,Object> map = new HashMap<>();
        PageHelper.startPage(page,limit);
        List<ShareContent> list = service.getShareFile(shareName);
        PageInfo<ShareContent> pageInfo = new PageInfo<ShareContent>(list);
        map.put("code",0);
        map.put("msg","");
        map.put("count",pageInfo.getTotal());//获取总个数
        map.put("data",pageInfo.getList());//获取数据
        return map;
    }

    @RequestMapping("deleteShare")
    @ResponseBody//空跳转
    public Map<String,Object> deleteShare(String shareName,Integer id) {//map为springmvc上传内容类型,获取上传文件file信息，“file”为底层所传
        Map<String, Object>map=new HashMap<>();
        service.deleteShare(shareName,id);
        map.put("code", 0);
        map.put("msg", "取消分享成功");
        return map;
    }
}
